package com.jic.market.impl.coupon;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.market.entity.coupon.CouponTrigger;
import com.jic.market.mapper.coupon.CouponTriggerMapper;
import com.jic.market.service.coupon.CouponTriggerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 优惠券商品关联表
 *
 * @author : seven
 * @version : v1.0.0
 * @email : 774329481@qq.com
 * @since : 2020-03-15 08:30:01
 */
@Service
public class CouponTriggerServiceImpl implements CouponTriggerService {

    @Autowired
    private CouponTriggerMapper couponTriggerMapper;

    @Override
    public Long insert(CouponTrigger couponTrigger) {
        couponTrigger.setDeleteFlag(false);
        long flag = couponTriggerMapper.insert(couponTrigger);
        return flag;
    }

    @Override
    public Long delete(String promotionId) {
        return couponTriggerMapper.delete(promotionId);
    }

    @Override
    public Long update(CouponTrigger couponTrigger) {
        return couponTriggerMapper.update(couponTrigger);
    }

    @Override
    public CouponTrigger queryByPrimaryKey(Long id) {
        return couponTriggerMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<CouponTrigger> query(CouponTrigger couponTrigger) {
        return couponTriggerMapper.query(couponTrigger);
    }

    @Override
    public PageResult<CouponTrigger> queryPage(CouponTrigger couponTrigger, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<CouponTrigger> list = couponTriggerMapper.queryPage(startIndex, pageQuery.getLimit(), couponTrigger);
        long count = couponTriggerMapper.queryPageCount(couponTrigger);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}